#ifndef USER_H
#define USER_H

#include <QObject> 

#include "cookiejar.h"

class QWebView;
class OAuthTokenPair;

/*
 * User class: 
 *
 * Handle authentication and user-specific data.
 * This is following the singleton paradigm to allow global use of one instance.
 *
 * Authentication:
 * Provides a storage-agnostic interface for User Credentials.
 * Uses CookieJar internally for storing.
 */

class User : public QObject {
    Q_OBJECT

    public:
        bool isLoggedIn();
        static User * instance(); // return active instance
        void loadFromBrowser( QWebView * ); // load login information from browser (cookies)
        QString username();
        OAuthTokenPair tokenPair();

    public slots:
        void startLogin();
        void logout(); // logout and remove login data from storage
        void login( QString username, OAuthTokenPair tok ); // try logging in with OAuthTokenPair
        void init(); // read data from storage and try to login

    protected:
        User(); // disable instantiation

    signals:
        void loginStartRequest();
        void loggedIn();
        void loggedOut();

    private:
        static User * sInstance; // the one active account
        OAuthTokenPair mTokenPair;
        QString mUsername;
        bool mIsLoggedIn;
        CookieJar * mCookieJar;
};

#endif
